﻿@using ORM.Areas.Admin.Models;
@using ORM.Framework.Security;
<div id="sidebar">
    <div id="sidebar-wrapper">
        <a href="@Url.Action("Index", "AdminHome")" >
            <img id="logo" src="@Url.Content("~/Content/images/fixtech7_70.png")" alt="Admin logo" style="width: 100px; height: 22px"/></a>
        <div id="profile-links">
            Hello, @Html.ActionLink(SecurityHelper.CurrentUser.UserInfo.Username.Truncate(25), "Profile", "Account", new { area = (string)null }, new { title = string.Format("{0} ({1})", SecurityHelper.CurrentUser.UserInfo.Username, SecurityHelper.CurrentUser.UserInfo.Email) })
            <br />
            @Html.ActionLink("View site", "Index", "Home", routeValues: new { area = (string)null }, htmlAttributes: null)
            |
            @Html.ActionLink("Logout", "Logoff", "Account", routeValues: new { area = (string)null }, htmlAttributes: null)
        </div>
        <ul id="main-nav">
            @foreach (var parent in AdminMenuCollection.Items)
            {
                bool shouldDisplay = parent.Children.Any(i => SecurityHelper.CurrentUser.HasPermission(i.RequiredPermission));
                if (shouldDisplay)
                {
                    bool isParentSelected = parent.Name == ViewBag.MenuGroup;
                    <li><a href="#" class="nav-top-item@(isParentSelected ? " current" : "")">
                        @parent.Text</a>
                        <ul>
                            @foreach (var child in parent.Children)
                            {
                                if (SecurityHelper.CurrentUser.HasPermission(child.RequiredPermission))
                                {
                                    bool isChildSelected = isParentSelected && child.Name.Equals(ViewBag.MenuName);
                                <li>
                                    @{
                                    if (isChildSelected)
                                    {
                                        @Html.ActionLink(child.Text, child.Action, child.Controller, routeValues: null, htmlAttributes: new { @class = "current" })
                                    }
                                    else
                                    {
                                        @Html.ActionLink(child.Text, child.Action, child.Controller)
                                    }
                                    }
                                </li>
                                }
                            }
                        </ul>
                    </li>
                }
            }
        </ul>
    </div>
</div>
